package com.handpay.nocardpay.baselibrary.qualificationinfo.view.fragment;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.commbase.view.fragment.BaseFragment;
import com.handpay.nocardpay.baselibrary.utils.BitmapLoaderNew;
import com.handpay.nocardpay.baselibrary.utils.DialogUtils;

/**
 * Created by fplei on 2017/8/16.
 * 查看大图
 */

public class BigPictureFragment extends BaseFragment {
    private ImageView iv_photo,iv_close;
    public static BigPictureFragment newInstance(String uri) {
        Bundle args = new Bundle();
        args.putString("imageUri",uri);
        BigPictureFragment fragment = new BigPictureFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_bigpicture;
    }

    @Override
    public void initView(View view) {
        iv_photo=(ImageView)view.findViewById(R.id.iv_photo);
        iv_close=(ImageView)view.findViewById(R.id.iv_close);
    }

    @Override
    public void initListener() {
        iv_close.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                BigPictureFragment.this.pop();
            }
        });
    }

    @Override
    public void initData(Bundle savedInstanceState) {
       String uri= getArguments().getString("imageUri","");
        if(!TextUtils.isEmpty(uri)) {
            BitmapLoaderNew.BitmapLoaderListener listener = new BitmapLoaderNew.BitmapLoaderListener() {
                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    iv_photo.setImageBitmap(loadedImage);
                }
            };
            BitmapLoaderNew.getInstance(getContext()).loadImage(uri, listener);
        }else{
            DialogUtils.showToast(_mActivity,"error:picture url is null!");
        }
    }
}
